﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BusinessObjects.BussinessVoucher;
using DataObjects.Shared;
using DataObjects.StandartInterfaces.Voucher;

namespace DataObjects.ADO.SqlServer.Voucher
{
    /// <summary>
    /// 
    /// </summary>
    public class SqlServerFixedAssetVoucherDetailDao : IFixedAssetVoucherDetailDao
    {


        public List<FixedAssetVoucherDetail> GetFixedAssetVoucherDetailsByFixedAssetVoucher(long refId)
        {
            throw new NotImplementedException();
        }

        public FixedAssetVoucherDetail GetFixedAssetVoucherDetail(long fixedAssetVoucherDetailId)
        {
            const string sql = @"uspGet_FixedAssetVoucherDetail_ByID";
            object[] parms = { "@EmployID", fixedAssetVoucherDetailId };
            return Db.Read(sql, CommandType.StoredProcedure, Make, parms);
        }

        /// <summary>
        /// Inserts the fixedAssetVoucherDetail.
        /// </summary>
        /// <param name="fixedAssetVoucherDetail">The fixedAssetVoucherDetail.</param>
        /// <returns></returns>
        public string InsertFixedAssetVoucherDetail(FixedAssetVoucherDetail fixedAssetVoucherDetail)
        {
            const string sql = "uspInsert_FixedAssetVoucherDetail";
            return Db.Insert(sql, CommandType.StoredProcedure, Take(fixedAssetVoucherDetail));
        }

        /// <summary>
        /// Updates the fixedAssetVoucherDetail.
        /// </summary>
        /// <param name="fixedAssetVoucherDetail">The fixedAssetVoucherDetail.</param>
        /// <returns></returns>
        public string UpdateFixedAssetVoucherDetail(FixedAssetVoucherDetail fixedAssetVoucherDetail)
        {
            const string sql = "uspUpdate_FixedAssetVoucherDetail";
            return Db.Update(sql, CommandType.StoredProcedure, Take(fixedAssetVoucherDetail));
        }

        /// <summary>
        /// Deletes the fixedAssetVoucherDetail.
        /// </summary>
        /// <param name="fixedAssetVoucherDetail">The fixedAssetVoucherDetail.</param>
        /// <returns></returns>
        public string DeleteFixedAssetVoucherDetail(FixedAssetVoucherDetail fixedAssetVoucherDetail)
        {
            const string sql = @"uspDelete_FixedAssetVoucherDetail";
            object[] parms = { "@RefDetailID", fixedAssetVoucherDetail.RefDetailId };
            return Db.Delete(sql, CommandType.StoredProcedure, parms);
        }
        /// <summary>
        /// The make
        /// </summary>
        private static readonly Func<IDataReader, FixedAssetVoucherDetail> Make = reader =>
          new FixedAssetVoucherDetail
          {
              RefId = reader["RefID"].AsLong(),
              RefDetailId = reader["RefDetailID"].AsLong(),
              FixedAssetId = reader["FixedAssetID"].AsInt(),
              AccountNumber = reader["AccountNumber"].AsString(),
              CorrespondingAccountNumber = reader["CorrespondingAccountNumber"].AsString(),
              Description = reader["Description"].AsString(),
              Quantity = reader["Quantity"].AsInt(),
              UnitPrice = reader["UnitPrice"].AsDecimal(),
              Amount = reader["Amount"].AsDecimal(),
              VoucherTypeId = reader["VoucherTypeID"].AsLong(),
              AutoBusinessId = reader["AutoBusinessID"].AsLong(),
              ProjectId = reader["ProjectID"].AsLong(),
              DepartmentId = reader["DepartmentID"].AsLong(),
              AccountNumberVat = reader["AccountNumberVAT"].AsString(),
              AmountVat = reader["AmountVAT"].AsDecimal()
          };

        /// <summary>
        /// Takes the specified employ test.
        /// </summary>
        /// <returns></returns>
        private static object[] Take(FixedAssetVoucherDetail faIncrementDetail)
        {
            return new object[]  
            {
                @"RefId", faIncrementDetail.RefId,
                @"RefDetailID", faIncrementDetail.RefDetailId,
                @"AccountNumber", faIncrementDetail.AccountNumber,
                @"CorrespondingAccountNumber", faIncrementDetail.CorrespondingAccountNumber,
                @"AutoBusinessID", faIncrementDetail.AutoBusinessId,
                @"FixedAssetID",faIncrementDetail.FixedAssetId,
                @"ProjectID",faIncrementDetail.ProjectId,
                @"VoucherTypeID",faIncrementDetail.VoucherTypeId,
                @"AmountOC",faIncrementDetail.Amount,
                @"DepartmentId",faIncrementDetail.DepartmentId,
                @"Description",faIncrementDetail.Description,
                @"Quantity",faIncrementDetail.Quantity,
                @"UnitPrice",faIncrementDetail.UnitPrice,
                @"AccountNumberVAT",faIncrementDetail.AccountNumberVat,
                @"AmountVAT", faIncrementDetail.AmountVat
            };
        }
    }
}
